﻿using Corina.Datamodel.Entities;
using Corina.Enumerations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Corina.DataContext.Service
{
    public class SpecimenKindService : ServiceBase
    {
        public List<SpecimenKindInfo> GetAllItems(string connectionString)
        {
            return DbOperator.GetEntities<SpecimenKindInfo>(connectionString, new List<string>() { }, new List<object>() { });
        }

        public bool Update(string connectionString, int id, string title)
        {
            return DbOperator.UpdateEntityById<SpecimenKindInfo>(connectionString, id, new List<string> { "Title" }, new List<object>() { title });
        }

        public bool Remove(string connectionString, int id)
        {
            return DbOperator.RemoveEntityById<SpecimenKindInfo>(connectionString, id);
        }

        public ResultValue Insert(string connectionString, string title)
        {
            if (Exist(connectionString, title))
            {
                return ResultValue.Exists;
            }
            bool flag = DbOperator.UpdateEntity(connectionString, new SpecimenKindInfo() { Title = title }, EntityOperation.Insert);
            return flag ? ResultValue.Succeed : ResultValue.Failed;
        }

        public bool Exist(string connectionString, string title)
        {
            return DbOperator.Exists<SpecimenKindInfo>(connectionString, new List<string>() { "Title" }, new List<object>() { title });
        }
    }
}
